package org.aurora.core.biz.controller.api;

import java.io.Serializable;

public class HttpResponse<T> implements Serializable {

    private boolean success;

    private String errorMsg;

    private int code;

    private T data;

    public static <T> HttpResponse<T> buildSuccess(T data) {
        HttpResponse<T> response = new HttpResponse<>();
        response.setData(data);
        response.setSuccess(true);
        return response;
    }

    public static <T> HttpResponse<T> buildSuccess() {
        return HttpResponse.buildSuccess(null);
    }

    public static <T> HttpResponse<T> buildFail(int code, String errorMsg) {
        HttpResponse<T> response = new HttpResponse<>();
        response.setCode(code);
        response.setErrorMsg(errorMsg);

        return response;
    }

    public static <T> HttpResponse<T> buildFail(int code) {
        return HttpResponse.buildFail(code, null);
    }

    public static <T> HttpResponse<T> buildFail(String errorMsg) {
        return HttpResponse.buildFail(0, errorMsg);
    }

    public static <T> HttpResponse<T> buildFail() {
        return HttpResponse.buildFail(0, null);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
